home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Utilities / Programming / EnterAct 3.5 / Drag_on Modules / hAWK programs / $RoughIndexer < prev    next >
Encoding:
Text File  |  1992-04-05  |  1.4 KB  |  45 lines  |  [TEXT/KEEN]

  1. #$RoughIndexer: towards generating a list of words to appear
  2. #in an index - skips common words (see $WordFrequency), prints
  3. #each word followed by all line locations. If you de-comment the
  4. #sorting lines that begin with '#%', and comment out the for-loop
  5. #at the beginning of the END block
  6. # (both of these in the END block), this will also sort the words
  7. #before printing. This is just a test-jig for trying out notions
  8. #about automating the task of index generation - ask anyone and
  9. #they'll tell you it's impossible. Now that's a challenge.
  10.  
  11. #This simple first version generates about 10 times too many
  12. #raw entries. Your mission, should you choose to accept it, is
  13. #to make it smart enough to be useful. If you succeed, you get
  14. #to be famous.
  15.  
  16. BEGIN {OFS = "\t"
  17.     commonfile = STDPATH "Drag_on Modules:hAWK programs:" "common words"
  18.     while (getline < commonfile > 0)
  19.         {
  20.         for ( k = 1; k <= NF; k++)
  21.             common[$k] = 1
  22.         }
  23.     close(commonfile)
  24.     $0 = ""
  25.     }
  26.  
  27.     { gsub(/[^A-Za-z0-9$'-]/, " ")
  28.       for ( k = 1; k <= NF; k++)
  29.           {
  30.         if (length($k) > 1 && !($k in common))
  31.               indexLines[$k] = indexLines[$k] "\t" FNR
  32.         }
  33.     }
  34. END { 
  35.         for (w in indexLines) #comment out if sorting
  36.             print w, indexLines[w] # comment out if sorting
  37.       #de-comment following lines for sorting
  38.       ##%for (w in indexLines)
  39.         ##%linear[++m] = w "\t\t" indexLines[w]
  40.       ##%sort(linear, ind, "d")
  41.       ##%for (j = 1; j <= m; ++j)
  42.           ##%print linear[ind[j]]
  43.     }
  44.  
  45.